//
//  UIBarButtonItem+Extensions.swift
//  GitWeibo
//
//  Created by 胡金东 on 2017/5/22.
//  Copyright © 2017年 胡金东. All rights reserved.
//

import Foundation



extension UIBarButtonItem{
    
    /// 创建UIBarButtonItem
    ///
    /// - Parameters:
    ///   - title: title
    ///   - titleColorNormal: 正常字体颜色
    ///   - titleColorHigh: 高亮字体颜色
    ///   - titleFont: 字体大小 默认16
    ///   - target: target
    ///   - action: action
    ///   - isBack: ture 显示返回箭头 false 不显示箭头
    convenience init(title:String,titleColorNormal:UIColor,titleColorHigh:UIColor,titleFont:CGFloat = 16,target:Any,action:Selector,isBack:Bool = false) {
        
        let btn = UIButton(type: .custom)

        if isBack {
            let imageName = "navigationbar_back_withtext"
            
            btn.setImage(UIImage(named:imageName), for: .normal)
            btn.setImage(UIImage(named:imageName + "_highlighted"), for: .highlighted)
            btn.sizeToFit()
        }
        
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(titleColorNormal, for: .normal)
        btn.setTitleColor(titleColorHigh, for: .highlighted)
        btn.addTarget(target, action: action, for: .touchUpInside)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: titleFont)
        /// - 不写不显示
        btn.sizeToFit()
        /// -  self.init 实例化 UIBarButtonItem
        self.init(customView:btn)
       }

}
